const {md5Encry,send} = require("@/zy-common//utils")
const {selectUser} = require("../code/code.service")

const verifyUser = async (ctx,next) => {
  try {
    const {phone,code} = ctx.request.body;
    let user = await selectUser(phone)
    if(Object.keys(user)?.length === 0){
      return send(ctx,200,'-1','该手机号不存在,请重新发送验证码')
    }
    //验证码手机和验证码
    if(md5Encry(code) !== user.code){
      return send(ctx,200,'-1','您输入的验证码不正确')
    }

    ctx.user = user
    await next()
  } catch (error) {
    console.log(error);
  }
}

module.exports = {
  verifyUser
}